
<?php
extract($_POST);
extract($_GET);
include 'conexion.php';
//$base= "ucg - copia";
$tabla = "compra1";
//$conexion=mysql_connect("localhost","root","");
//mysql_select_db($base,$conexion);
$resultado = mysql_query("SELECT * FROM $tabla WHERE cod_c='$Modificar'", $conexion);
$registro = mysql_fetch_row($resultado);
?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Reporte Compra</title>

        <style type="text/css">
            <!--
            body,td,th {
                font-family: Arial, Helvetica, sans-serif;
                font-size: 12px;
                color: #000000;
            }
            body {
                background-color: #FFFFFF;
            }
            a {
                font-family: Courier New, Courier, mono;
                font-size: 14px;
                color: #000000;
            }
            a:visited {
                color: #000000;
            }
            a:hover {
                color: #000000;
            }
            a:active {
                color: #999999;
            }
            -->
        </style>

        <style type="text/css">
            <!--
            @import url("tablas.css");
            a:link {
                color: #000000;
            }
            .style5 {
                font-size: 14px;
                font-weight: bold;
                color: #000000;
            }
            .style9 {
                color: #000000;
                font-weight: bold;
            }
            .style4 {font-size: 12px}
            .style12 {font-size: 14px; color: #000000; }
            .Estilo1 {font-size: xx-small}
            .Estilo3 {font-size: 10; }
            -->
        </style>
    </head>
    <body>
        <table width="25%" border="0" class="celdatodo" align="center">
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <tr>
                <td align="right"><strong>Fecha:</strong><? echo " $registro[3]"; ?></td>
            </tr>
        </table>
        <?
        if ($registro[2] == 1)
            $tipo = "DE COMPRA";
        if ($registro[2] == 2)
            $tipo = "DE SERVICIO";
        if ($registro[2] == 3)
            $tipo = "INTERNA";
        ?>
        <table width="100%" border="1" class="celdatodo" align="center">
<? $resul = mysql_query("SELECT * FROM proveedor WHERE rif='$registro[4]'", $conexion);

        $regis = mysql_fetch_row($resul); ?>
            <tr>
                <td rowspan="2" colspan="2">PROVEEDOR: <? echo utf8_encode($regis[1]); ?></td>
                <td rowspan="2">RIF: <? echo $registro[4]; ?></td>
                <td colspan="2" align="center">REGISTRO DE PROVEEDORES</td>
            </tr>
            <tr>
                <td>Nº S.N.C <?php echo " $regis[4]" ?> </td>
                <td>Nº INTERNO: <?php echo " $regis[9]" ?></td>
            </tr>
            <tr>
                <td rowspan="2">LUGAR DE ENTREGA: <?php echo " $registro[14]" ?></td>
                <td rowspan="2" colspan="2">FORMA DE PAGO: <?php
                    if ($registro[13] == 1
                        )$formadepago = 'Orden de Pago';
                    if ($registro[13] == 2
                        )$formadepago = 'Directa';
                    if ($registro[13] == 3
                        )$formadepago = 'Crédito';
                    if ($registro[13] == 4
                        )$formadepago = 'Avances';
                    if ($registro[13] == 5
                        )$formadepago = 'Otros';
                    echo " $formadepago"
?></td>
                <td colspan="2" align="center" rowspan="2">PLAZO DE ENTREGA:
<?php
                    if ($registro[11] == 1
                        )$plazodeentrega = ' Dias Habiles';
                    if ($registro[11] == 2
                        )$plazodeentrega = ' Dias Continuos';
                    if ($registro[11] == 3
                        )$plazodeentrega = ' Meses Habiles';
                    if ($registro[11] == 4
                        )$plazodeentrega = ' Meses Continuos';
                    echo " $registro[12] $plazodeentrega ";
?>
                        </td>

                    </tr>
                    <tr>
                        <td colspan="3" align="center"></td>
                    </tr>
                    <tr>
                        <td align="center">CÓDIGO PRESUPUESTARIO</td>
                        <td colspan="2" align="center">DENOMINACIÓN</td>
                        <td colspan="2" align="center">MONTO Bs.</td>
                    </tr>
                        <?
                        $query = "select distinct(cuenta) from id_compra where cod_c='$registro[0]' group by cuenta";
                        $queryejecuta = mysql_query($query, $conexion);
                        while ($array = mysql_fetch_row($queryejecuta)) {
 ?>
                <tr>
                    <td align="center">
                        <span class="Estilo1">
<?php
                            echo utf8_encode($array[0]);
?>
                            </span>
                        </td>

                        <td align="center" colspan="2">
                            <span class="Estilo1">
                    <?php
                            $query2 = "select detalle from cuentas where cuenta='$array[0]'";
                            $query2ejecuta = mysql_query($query2, $conexion);
                            $array2 = mysql_fetch_row($query2ejecuta);
                            echo utf8_encode($array2[0]);
                    ?>
                            </span>
                        </td>
                        <td align="right" colspan="2">
            <?php
                            $query3 = "select sum(cantidad*pre_unit) from id_compra where cod_c='$registro[0]' and cuenta='$array[0]'";
                            $query3ejecuta = mysql_query($query3, $conexion);
                            $array3 = mysql_fetch_row($query3ejecuta);
                            if ($tipo == "INTERNA") {
                                $array3[0] = number_format($array3[0], 4, ",", ".");
                            } else {
                                $array3[0] = number_format($array3[0], 2, ",", ".");
                            }
                            echo utf8_encode($array3[0]);
            ?>
                    </td>
                </tr>
<?php
                        }
                        $query4 = "select distinct(cuenta_iva) from id_compra where cod_c='$registro[0]' group by cuenta_iva";
                        $query4ejecuta = mysql_query($query4, $conexion);
                        while ($array4 = mysql_fetch_row($query4ejecuta)) {
                            if ($array4[0] != "") {
?>

                    <tr>
                        <td align="center">
                            <span class="Estilo1">
<?php
                                echo $array4[0];
?>
                                </span>
                            </td>
                            <td align="center" colspan="2">
                                <span class="Estilo1">
                    <?php
                                $query5 = "select detalle from cuentas where cuenta='$array4[0]'";
                                $query5ejecuta = mysql_query($query5, $conexion);
                                $array5 = mysql_fetch_row($query5ejecuta);
                                echo $array5[0];
                    ?>
                                </span>
                            </td>
                            <td align="right" colspan="2">
            <?php
                                $query6 = "select sum(valor_iva) from id_compra where cod_c='$registro[0]' and cuenta_iva='$array4[0]'";
                                $query6ejecuta = mysql_query($query6, $conexion);
                                $array6 = mysql_fetch_row($query6ejecuta);
                                if ($tipo == "INTERNA") {
                                    $array6[0] = number_format($array6[0], 4, ",", ".");
                                } else {
                                    $array6[0] = number_format($array6[0], 2, ",", ".");
                                }
                                echo $array6[0];
            ?>
                                    </td>
                                </tr>

            <?php
                            }
                        }
            ?>
                        <tr>
                            <td align="center" colspan="5"><strong>ESPECIFICACIONES DE LA ORDEN <?php echo $tipo ?></strong></td>
                        </tr>
                        <tr>
                            <td align="center"><strong>CANTIDAD</strong></td>
                            <td align="center"><strong>UNIDAD</strong></td>
                            <td align="center"><strong>DESCRIPCIÓN</strong></td>
                            <td align="center"><strong>PRECIO UNITARIO</strong></td>
                            <td align="center"><strong>TOTAL</strong></td>
                        </tr>
                        <? $resu = mysql_query("SELECT * FROM  id_compra WHERE cod_c='$registro[0]'", $conexion);

                        while ($reg = mysql_fetch_row($resu)) { ?>
                <tr bordercolor="#000000">
                    <td align="center" width="17 %">

                        <span class="Estilo1">
<?
                            if ($tipo == "INTERNA") {
                                $cant = round($reg[2], 4);
                            } else {
                                $cant = round($reg[2], 2);
                            }
                            echo $cant; ?></span></td>

                    <td width="15 %">
                        <span class="Estilo1">
                        <?php echo $reg[10]; ?>
                        </span></td>
                    <td>
                        <span class="Estilo1"><? echo "$reg[3]"; ?></span> </td>
                    <td align="right" valign="middle">
                        <span class="Estilo1">
                        <?
                            if ($tipo == "INTERNA") {
                                $uni = number_format($reg[4], 4, ",", ".");
                            } else {
                                $uni = number_format($reg[4], 2, ",", ".");
                            }
                            echo $uni; ?>
                        </span> </td>
                    <td align="right" valign="middle">

                        <span class="Estilo1">
            <?
                            $totaluni = $reg[2] * $reg[4];

                            if ($tipo == "INTERNA") {
                                $totaluni1 = number_format($totaluni, 4, ",", ".");
                            } else {
                                $totaluni1 = number_format($totaluni, 2, ",", ".");
                            }
                            echo $totaluni1; ?>
                            </span></td>
                    </tr>
                    <? $subtotal = $subtotal + $totaluni;
                        } ?>
                <tr>
                    <td colspan="4" align="right" class="Estilo1">SUB-TOTAL</td>
                    <td align="right"> <?
                        if ($tipo == "INTERNA") {
                            $subtotal1 = number_format($subtotal, 4, ",", ".");
                        } else {
                            $subtotal1 = number_format($subtotal, 2, ",", ".");
                        }
                        echo $subtotal1;
                    ?></td>
                        </tr>
                    <?
                        $re = mysql_query("SELECT sum(valor_iva),iva FROM  id_compra WHERE cod_c='$registro[0]' and iva!='0' group by iva", $conexion);

                        while ($iva = mysql_fetch_row($re)) {
                    ?>
                    <tr>
                        <td colspan="4" align="right">IVA <?php echo $iva[1] ?></td>
                        <td align="right"><?php
                            $totaliva = $iva[0];

                            if ($tipo == "INTERNA") {
                                $totalivat = number_format($totaliva, 4, ",", ".");
                            } else {
                                $totalivat = number_format($totaliva, 2, ",", ".");
                            }
                            echo $totalivat; ?></td>
                    </tr>
                    <?php } ?>
                <tr>
                    <td colspan="4" align="right"><strong>TOTAL</strong></td>
                    <td align="right"><?php
                        $total = $subtotal + $totaliva;
                        if ($tipo == "INTERNA") {
                            $total1 = number_format($total, 4, ",", ".");
                        } else {
                            $total1 = number_format($total, 2, ",", ".");
                        }
                        echo $total1;
                    ?></td>
                </tr>
                <tr>
                    <td colspan="4"  class="celdatodo">&nbsp;</td>
                </tr>
                <tr><td colspan="2"  class="celdatodo">.</td>
                    <td colspan="2"  class="celdatodo">&nbsp;</td>
                </tr>
                <tr>
                    <td height="28" class="celdatodo" ><div align="center" class="style4"><strong>ELABORADO POR: </strong></div></td>
                    <td class="celdatodo" colspan="2"><div align="center" class="style4"><strong>REVISADO POR:</strong></div></td>
                    <td width="26%" class="celdatodo" colspan="2"><div align="center" class="style4"><strong>APROBADO POR: </strong></div></td>
                </tr>
                <tr>
                    <td colspan="7" class="celdatodo" >&nbsp;</td>
                </tr>
                <tr>
                    <td colspan="7" class="celdatodo" ><div align="center"></div>      <div align="center"></div>      <div align="center"></div></td>
                </tr>
                <tr>
                    <td class="celdatodo"><div align="center" class="Estilo3"><? echo $registro[10]; ?></div></td>
                    <td class="celdatodo" colspan="2"><div align="center" class="Estilo3"><? echo $registro[6]; ?></div></td>
                    <td class="celdatodo" colspan="2"><div align="center" class="Estilo3"><? echo $registro[7]; ?></div></td>

                </tr>
                <tr>
                    <td class="celdatodo"><div align="center" class="Estilo3">Asistente Administrativo</div></td>
                    <td class="celdatodo" colspan="2"><div align="center" class="Estilo3">Administradora</div></td>
                    <td class="celdatodo" colspan="2"><div align="center" class="Estilo3">Jefe de la Unidad de Control de Gestión</div></td>

                </tr>
                <tr><td colspan="2"  class="celdatodo">.</td>
                    <td colspan="2"  class="celdatodo">&nbsp;</td>
                </tr>
                <tr>
                    <td  colspan="5" class="celdatodo"><div align="left" class="style4"><strong>RECIBIDO POR: </strong></div></td>
                </tr>
                <tr>
                    <td  colspan="5" class="celdatodo"><div align="left" class="style4">Nombre: </div></td>
                </tr>
                <tr>
                    <td  colspan="5" class="celdatodo"><div align="left" class="style4">Nº de C.I. </div></td>
                </tr>
                <td colspan="5" class="celdatodo"><div align="left"><strong>Firma y Sello    </strong></div></td>
<?PHP
                        if ($registro[2] == 1 or $registro[2] == 3)
                            $tipo2 = "DE LA COMPRA";
                        if ($registro[2] == 2)
                            $tipo2 = "DEL SERVICIO";
                        ?>
                <tr>
            <td colspan="2" class="celdatodo"><div align="left"><strong>ANEXO: CONDICIONES GENERALES <?php echo $tipo2 ?></strong></div></td>
            </tr>
        </table>
    </body>
</html>
